import {permissionList}  from '@/config/PermissionConfig'
import { ref, onMounted, useTemplateRef } from 'vue';
import {storeToRefs} from 'pinia'
import {type R} from "@/types/R"
import {request} from "@/utils/Request"
import {ElMessage, ElMessageBox} from "element-plus"
import {type PageInfo} from "@/types/PageInfo"
import {randomId} from "@/utils/IdUtils"
import { usePayOrderStore } from './PayOrderStore';
import { useApplicationStore } from '@/pages/application/applicationStore'
import type { PayOrderVO, PayBackAO, PayBackVO } from './PayOrderTypes';
import { usePayBackOrderStore } from './PayBackOrderStore';

export const usePayBackOrderHooks = function(){
    let payBackOrderStore = usePayBackOrderStore()
    let {
        payBackOrderDialog, selectPayBackOrderAO
    } = storeToRefs(payBackOrderStore)

    let applicationStore = useApplicationStore();
    let {isCollapse} = storeToRefs(applicationStore)

    const backReset = ()=>{
        let payDtoId = selectPayBackOrderAO.value.payDtoId
        selectPayBackOrderAO.value = {}
        selectPayBackOrderAO.value.payDtoId = payDtoId
        backSelect()
    }

    onMounted(()=>{
        backSelect()
    })

    // 退款记录
    let backSelectLoading = ref<boolean>(false)
    let backPageInfo = ref<PageInfo<PayBackVO>>()
    const backSelect = async ()=>{
        backSelectLoading.value = true
        let r:R<PageInfo<PayBackVO>> = await request.post("/pay/selectPayBackOrder",selectPayBackOrderAO.value)
        if(r.code == "success"){
            backPageInfo.value = r.data
        }
        backSelectLoading.value = false
    }

    return {
        isCollapse, 
        payBackOrderDialog,
        selectPayBackOrderAO, backSelectLoading, backPageInfo,
        backReset, backSelect
    }
}
